 //控制层 
app.controller('userController' ,function($scope,$controller,userService,uploadFileService){
	$controller("commonController",{$scope:$scope});
	//注册用户
	$scope.register=function(){
		//比较两次输入的密码是否一致
		if($scope.password!=$scope.dpUser1.password){
			alert("两次输入密码不一致，请重新输入");
			$scope.dpUser1.password="";
			$scope.password="";
			return ;			
		}
		userService.add($scope.dpUser1,$scope.smsCode).success(
			function(response){
				if (response.object==null){
					alert(response.message);
					location.href="home-index.html";
				}else{
					alert(response.object);
				}

			}		
		);
	}
    $scope.checkUsername=function(){
		userService.checkUsername($scope.dpUser1.username).success(
			function (response) {
				if (500==response.code){
					alert("用户名已存在")
				}
			}
		)
	}
	//发送验证码
	$scope.sendCode=function(){
		if($scope.dpUser1.phone==null || $scope.dpUser1.phone==""){
			alert("请填写手机号码");
			return ;
		}
		userService.sendCode($scope.dpUser1.phone).success(
			function(response){
				alert(response.object);
			}
		);		
	}
	//查询用户信息
	$scope.findOne=function(){
		userService.findOne().success(
			function(response){
				$scope.dpUser=response;
			}
		);
	}
	//完善用户基本信息
	$scope.update=function () {
		userService.update($scope.dpUser).success(
			function (response) {

			}
		);
	}
	//文件上传
	$scope.uploadFile=function () {
		uploadFileService.uploadFile().success(
			function (response) {
				if (200==response.code){
					$scope.dpUser.headPic=response.object;
				}else{
					alert(response.message)
				}
			}
		);
	}
});	
